clear all;clc;

q=[0.2,0.2,0.4,0.1,0.1];

n=length(q);

r=zeros(n,n);

rq=zeros(n,n);

for i=1:n

rq(i,:)=q;

[q,index]=sort(q);

r(i,:)=[index(1:n+1-i) zeros(1,i-1)];

q=[q(1)+q(2) q(3:n) 1];

end

c=cell(n,n);

for i=1:n

for j=1:n

c(i,j)={blanks(1)};

end

end

for row=n:-1:2

for col=1:n+1-row

if r(row,col)==1

c(row-1,1)={[char(c(row,col)), '0']};

c(row-1,2)={[char(c(row,col)), '1']};

else

c(row-1,r(row,col)+1)=c(row,col);

end

end

end


